/* Copyright Andy Mitchell 2007. No warranties */

function GmailDOM(gtdinboxPage){
	this._gtdinboxPage = gtdinboxPage;
	this._doc = gtdinboxPage.doc;
	this._window = gtdinboxPage.window;
	this._xmlHttpRequest = new GIXMLHttpRequest(gtdinboxPage);
}

GmailDOM.prototype.viewChange = function(gmail){
	this._gmail = gmail;
};

GmailDOM.prototype.element = function(name, gmail, doc, elActive){
try{
	gmail = (gmail && (typeof gmail!="undefined"))? gmail : this._gmail;
	this._gmail = gmail;
	if( gmail["get" + name] ) return gmail["get" + name]();
	
	doc = doc || this._doc;
	
	if( !elActive ){
		var elActive = gmail.getActiveViewElement();
		if( !elActive ){
			if( this._window && this._window.frames && this._window.frames[1] && this._window.frames[1].document ){
				elActive = this._window.frames[1].document.body;
			}else{
				elActive = doc.body;
			}
		}
		if( !elActive ) return;
	}
	
	
	switch(name){
		/* GENERAL */
		case "window":
			return elActive.ownerDocument.defaultView;
			break;
		case "document":
			return elActive.ownerDocument;
			break;
		case "action-combo":
			var result = doc.evaluate("//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//div[@class='QOD9Ec']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "action-combo-list":
			var result = doc.evaluate("//div[@class='Sn99bd']", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			for( var i = 0; i < result.snapshotLength; i++ ){
				if( result.snapshotItem(i).style.visibility!="hidden" ) return result.snapshotItem(i);
			}
			//return result.singleNodeValue;			
			break;
		case "email-address":
			var result = doc.evaluate("//div[@class='XoqCub']//div[@class='nQ6QTe']//nobr//b", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "alert-box":
			var result = doc.evaluate("//div[@class='n38jzf']//table[@class='cyVRte']//td[@class='m14Grb']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "search-box":
			var result = doc.evaluate("//div[@class='oF1kyb']//div[@class='tYBwhe']//input[@type='text']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "search-button":
			var result = doc.evaluate("//div[@class='oF1kyb']//div[@class='tYBwhe']//button[@type='button']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "search-row":
			var result = doc.evaluate("//div[@class='IY0d9c']//div[@class='XoqCub EGSDee']//div[@class='oF1kyb']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			var el = result.singleNodeValue;
			return el? el.parentNode : null;
			break;
			
		/* THREAD LIST */
		case "archive-button":
			var result = doc.evaluate("//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//button[@act='7']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "spam-button":
			var result = doc.evaluate("//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//button[@act='9']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "delete-button":
			var result = doc.evaluate("//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//button[@act='10']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "threadlist-refresh":
			var result = doc.evaluate("//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//div[@act='20']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "new-label-box":
			var result = doc.evaluate("//div[@class='jY0YJb']//div[@class='tQzAEe']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			var el = result.singleNodeValue;
			if( el ) el = el.parentNode;
			return el;
			break;
			
		/* NAVIGATION */
		case "nav-buckets":
			var result = doc.evaluate("//div[@class='XoqCub EGSDee']//div[@class='XoqCub ybaOyc']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "inbox-link":
			var result = doc.evaluate("//div[@class='diLZtc']//div[starts-with(@class,'yyT6sf')]//span[@class='zD5BAe']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "compose-mail":
			var result = doc.evaluate("//div[@class='diLZtc']//div[@class='NIPhib']//span[@class='zD5BAe']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "edit-labels":
			var result = doc.evaluate("//div[@class='diLZtc']//div[@class='nb1Q2b']//div[@class='Q9o7yd']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		

		/* CONVERSATION */
		case "conversation-header":
			var result = doc.evaluate("//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//td[@class='eWTfhb']//h1[@class='YfMhcb']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "conversation-subject":
			var result = doc.evaluate("//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//td[@class='eWTfhb']//h1[@class='YfMhcb']//span[@class='VrHWId']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		
		/* COMPOSE */
		case "rich-textarea":
			var elBody = null;
			var w = this.element("window");
			for( var i = 0; i < w.frames.length; i++ ){
				if( w.frames[i].document.body.className.indexOf("editable")>-1 ){
					elBody = w.frames[i].document.body;
					break;
				}
			}
			return elBody;
			break;
		case "plain-textarea":
			var result = doc.evaluate("//td[@class='opUkHb']//textarea[@class='iE5Yyc']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "compose-to":
			var result = doc.evaluate("//div[@class='uQLZXb']//form//table[@class='wHcYVb']//textarea[@class='mMl8gd']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "compose-table":
			var result = doc.evaluate("//div[@class='uQLZXb']//form//table[@class='wHcYVb']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;			
		
		
		/* CONTACTS */
		case "contacts-iframe":
			var els = doc.getElementsByTagName("IFRAME");
			for( var i = 0; i < els.length; i++ ){
				if( els[i].getAttribute("src") && els[i].getAttribute("src").indexOf("/ContactManager")>-1 ){
					return els[i];
				}
			}
			break;
		case "contacts-frame-body":
			var w = this.element("window");
			for( var i = 0; i < w.frames.length; i++ ){
				if( w.frames[i].location.href.indexOf("ui/ContactManager")>-1 ){
					return w.frames[i].document.body;
				}
			}
			
			// Earlier code (to remove if stable)
			var w = this._window.frames[1];
			for( var i = 0; i < w.frames.length; i++ ){
				if( w.frames[i].location.href.indexOf("ui/ContactManager")>-1 ){
					return w.frames[i].document.body;
				}
			}
			break;
		case "contacts-manager-tabs":
			return doc.getElementById("manager-group-list");
			break;
		case "contacts-manager-list":
			return doc.getElementById("manager-contact-list");
			break;
		case "contacts-pane":
			return doc.getElementById("contact-pane");
			break;
			
		/* SETTINGS */
		case "labels-create-box":
			var result = doc.evaluate("//div[@class='XoqCub eGbrz']//tr[@class='GorKne']//td[@class='kN8OP']//input", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
		case "labels-last-row":
			var result = doc.evaluate("//div[@class='XoqCub eGbrz']//tr[last()]//td[@class='lKvq2e']", elActive, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
			return result.singleNodeValue;
			break;
	}

}catch(e){
	if( GTDDEBUGMODE ) alert("gmaildom element\n" + e.toString());
}

};

GmailDOM.prototype.elements = function(name, gmail, doc, elActive){
try{
	gmail = (gmail && (typeof gmail!="undefined"))? gmail : this._gmail;
	this._gmail = gmail;
	
	doc = doc || this._doc;
	elActive = elActive || gmail.getActiveViewElement();
	switch(name){
		case "threadlist-allrows":
			return doc.evaluate( "//table[@class='N2mZ7b']//tr[starts-with(@class,'xweT7d')]", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			break;
		case "threadlist-rows-lastcol":
			return doc.evaluate( "//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//table[@class='N2mZ7b']//tr[starts-with(@class,'xweT7d')]//td[last()]", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			break;
		case "threadlist-rows-checkbox":
			return doc.evaluate( "//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//table[@class='N2mZ7b']//tr[starts-with(@class,'xweT7d')]//td//input[@type='checkbox']", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			break;
		case "threadlist-rows-checked-checkbox":
			var result = doc.evaluate( "//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//table[@class='N2mZ7b']//tr[starts-with(@class,'xweT7d AnqB9d rfza3e')]//td//input[@type='checkbox']", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			if( result.snapshotLength==0 ){
				result = doc.evaluate( "//div[@gtdviewid='" + this._gtdinboxPage.view("gtdviewid") + "']//table[@class='N2mZ7b']//tr[starts-with(@class,'xweT7d QhHSYc rfza3e')]//td//input[@type='checkbox']", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			}
			return result;
			break;
		case "contacts-list":
			return doc.evaluate( "//div[starts-with(@class,'row')]//div[@class='check']//input[@type='checkbox']", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			break;
		case "contacts-list-checked":
			return doc.evaluate( "//div[starts-with(@class,'row selected')]//div[@class='check']//input[@type='checkbox']", elActive, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			break;
	}
}catch(e){
	if( GTDDEBUGMODE ) alert("gmaildom elements\n" + e.toString());
}	
}

GmailDOM.prototype.parseElement = function(name, el){
try{
	var result = {};
	if( !el ) return;
	switch(name){
		case "thread-list-row":	// el is TR; extract check, names, label, subject, snippet, date
			var elTds = el.getElementsByTagName("TD");
			result.elCheck = elTds[0].getElementsByTagName("INPUT")[0];
			result.elStar = elTds[1].getElementsByTagName("IMG")[0];
			result.names = [];
			var elSpans = elTds[2].getElementsByTagName("SPAN");
			for( var i = 0; i < elSpans.length; i++ ){
				if( elSpans[i].getAttribute("email") ){
					result.names.push( [GIPROTOTYPE.decodeEntities(elSpans[i].innerHTML.replace(/<.+?>/g,"").replace(/\(\d+\)$/,"").replace(/\s?\.\s?$/,"")), GIPROTOTYPE.realEmail(elSpans[i].getAttribute("email"))] );
				}
			}
			result.labels = [];
			var elSpans = elTds[4].getElementsByTagName("SPAN");
			for( var i = 0; i < elSpans.length; i++ ){
				if( elSpans[i].className=="s75Nkf" ){	// it's a label (lots of b tags inside)
					result.labels.push( GIPROTOTYPE.trim(GIPROTOTYPE.decodeEntities(elSpans[i].innerHTML.replace(/<.+?>/g, ""))) );
				}
				if( elSpans[i].className=="bEeVec" ){	// it's snippet, and one before is subject
					result.subject = GIPROTOTYPE.trim(GIPROTOTYPE.decodeEntities(elSpans[i].previousSibling.innerHTML.replace(/<.+?>/g, "")));
					result.snippet = GIPROTOTYPE.trim(GIPROTOTYPE.decodeEntities(elSpans[i].innerHTML.replace(/<.+?>/g, "")));
				}else if( elSpans[i].parentNode.className=="HhG5wd" && elSpans[i].parentNode.childNodes.length==1 ){	// Subject, but no snippet (empty msg)
					result.subject = GIPROTOTYPE.trim(GIPROTOTYPE.decodeEntities(elSpans[i].innerHTML.replace(/<.+?>/g, "")));
				}
			}
			if( result.subject ) result.subject = result.subject.replace(/\s*?\(\d+.+?\)$/, "");	// strip things like Chat (177 lines); because thread code doesn't use it
			result.elDate = elTds[6].getElementsByTagName("SPAN")[0];
			result.date = result.elDate.innerHTML.replace(/<.+?>/g, "");
			result.fullDate = result.elDate.getAttribute("title");
			
			if( result.labels.length==0 && !result.subject ){	// pre-coloured-labels
			}
			break;
		case "contacts-list-item":	// el can be div text, div check, or input box - find parent 'row', and then extract contents
			var i = 0; 
			while( el.parentNode && i++<=4 ){
				if( el.className.indexOf("row")>-1 ) break;
				el = el.parentNode;
			}
			if( el.className.indexOf("row")==-1 ) return;
			var row = [];
			for( var i = 0; i < el.childNodes.length; i++ ){
				if( el.childNodes[i].className=="text" ){
					row[1] = el.childNodes[i].title;
					row[0] = el.childNodes[i].innerHTML;
					break;
				}
			}
			var els = el.getElementsByTagName("INPUT");
			row[2] = els[0];
			return row;
			break;
	}
	
	return result;
}catch(e){
	if( GTDDEBUGMODE ) alert("gmaildom parseElement\n" + e.toString());
}
};

GmailDOM.prototype.test = function(name, el){
try{
	//var result = {};
	switch(name){
		case "is-sent-mail":
			var elNav = this.element("nav-buckets");
			var elSentMail = elNav.firstChild.childNodes[3];
			if( elSentMail.className.indexOf("cBhtOe")>-1 ){	// selected
				return true;
			}
			break;
		case "thread-row-unread":
			return (el.className.indexOf("QhHSYc")>-1);
			break;
		case "thread-row":
			return (el.nodeName=="TR" && el.className.indexOf("xweT7d")==0);
			break;
		case "conversation-x":
			return (el.nodeName=="SPAN" && el.className=="tcLg2b");
			break;
		case "star":
			return ( el.nodeName=="IMG" && el.className.indexOf("iyUIWc")==0 );	// It's a star image
			break;
		case "star-on":
			return ( el.className.indexOf("kJv9nb")>-1 || el.parentNode.className.indexOf("n1QcP")>-1 );	// It's a star image
			break;
		case "contact-tab":
			if( el.nodeName=="DIV" && el.className=="text"){
				var found = false;
				var i = 0;
				while( i++ <=3 ){
					el = el.parentNode;
					if( el.id=="manager-group-list" ) return true;
				}
			}
			break;
		case "contacts-list-item-checkbox":
			return ( el.nodeName=="INPUT" && el.id.indexOf("CC")==0 && el.type.toLowerCase()=="text");	
			break;
		case "contacts-list-item-name":
			return ( el.nodeName=="DIV" && el.className=="text" && el.title.indexOf("@")>-1 );	
			break;
	}	
}catch(e){
	if( GTDDEBUGMODE ) alert("gmaildom test\n" + e.toString());
}
};


GmailDOM.prototype.extractSearchQueryFromURL = function(url){
	if( /\/(#search)/.test(url) ){
		var match = url.match( /\/#search\/(.+?)($|\/\w+$)/ );
		if( match ) return match[1];
	}else if( /\/(#label)/.test(url) ){
		var match = url.match( /\/#label\/(.+?)($|\/\w+$)/ );
		if( match ) return GIPROTOTYPE.searchableLabel( decodeURIComponent(match[1]) );
	}
	return "";
};


GmailDOM.prototype.search = function(query, currentOffset, number, callback, callbackFinish){
	http://mail.google.com/mail/?ui=2&ik=20dd9d8458&view=tl&start=0&num=25&rt=h&q=test&search=query
	var request = {};
	request.url = this.local("domain") + "?ui=2";
	request.url += "&ik=" + this.local("ik");
	request.url += "&rt=j&start=" + currentOffset + "&num=" + number + "&search=query&view=tl";
	request.url += "&q=" + encodeURIComponent(query);
	this._gtdinboxPage.unsafeWindow.console.log(request.url);
	request.query = query;
	request.callback = GIPROTOTYPE.bind(this, function(req){
				// Extract the json from the response
				
				var searchArray = null;
				var js = req.responseText.replace("while(1);", ""); //.replace(/_A\(.*?\)/g, "0");
				try{
					searchArray = this.element("window").wrappedJSObject.eval(js);
				}catch(e){
					if( GTDDEBUGMODE ) alert("GmailDOM search callback\n" + e.toString());
				}
				
				/*
				
				this._gtdinboxPage.unsafeWindow.console.log(js);
				try{
					var searchArray = eval(js);
				}catch(e){
					if( GTDDEBUGMODE ) alert("GmailDOM search callback\n" + e.toString());
				}
				try{
					var searchArray = json.parse(js);
				}catch(e){
					if( GTDDEBUGMODE ) alert("GmailDOM search callback 2\n" + e.toString());
				}
				try{
					var searchArray = this._gtdinboxPage.unsafeWindow.top.js.eval( js );
				}catch(e){
					if( GTDDEBUGMODE ) alert("GmailDOM search callback 3\n" + e.toString());
				}
				try{
					GIPROTOTYPE.bind( this._gtdinboxPage.unsafeWindow, function(){ 
						try{
							eval( js );
						}catch(e){
							if( GTDDEBUGMODE ) alert("GmailDOM search callback inner\n" + e.toString());
						}
					});
				}catch(e){
					if( GTDDEBUGMODE ) alert("GmailDOM search callback 4\n" + e.toString());
				}
				try{
					var searchArray = this._gtdinboxPage.window.eval( js );
				}catch(e){
					if( GTDDEBUGMODE ) alert("GmailDOM search callback 5\n" + e.toString());
				}
				var count = {open:0, close:0}
				js = js.replace( /\".+?\"/g, "" );
				js = js.replace( /\'.+?\'/g, "" );
				for( var i = 0; i < js.length; i++ ){
					if( js[i]=="[" ) count.open++;
					if( js[i]=="]" ) count.close++;
				}
				alert( "open: " + count.open + ", close: " + count.close );
				*/
				
				if(callback) callback(searchArray, request.query, currentOffset, callbackFinish);
		});
	this._xmlHttpRequest.process(request);
};


GmailDOM.prototype.addLabel = function(names, callback, finalCallback){
try{
	if( typeof names=="string" ) names = [names];
	
	var count = {i:0};
	for( var i = 0; i < names.length; i++ ){
		var request = {};
		request.url = this.local("domain") + "?ui=2";
		request.url += "&ik=" + this.local("ik");
		request.url += "&at=" + this.local("at");
		request.url += "&view=up&act=cc_" + encodeURI(names[i]) + "&rt=h";
		request.callback = GIPROTOTYPE.bind(this, function(){
					if(callback) callback();
					if( --count.i==0 ){
						if(finalCallback) finalCallback();
					}
			});
		count.i++;
		this._xmlHttpRequest.process(request);
	}
}catch(e){
	alert("gmaildom addLabel\n" + e.toString());
}
};
GmailDOM.prototype.renameLabel = function(replacements, callback, finalCallback){
try{
	if( typeof replacements[0]=="string" ) replacements = [replacements];	// should be [[,],[,]]
	
	var count = {i:0};
	for( var i = 0; i < replacements.length; i++ ){
		var request = {};
		request.url = this.local("domain") + "?ui=2";
		request.url += "&ik=" + this.local("ik");
		request.url += "&at=" + this.local("at");
		request.url += "&view=up&act=nc_" + encodeURI(replacements[i][0]) + "%5E" + encodeURI(replacements[i][1]) + "&rt=h";
		request.callback = GIPROTOTYPE.bind(this, function(){
				if(callback) callback();
				if( --count.i==0 ){
					if(finalCallback) finalCallback();
				}
			});
		count.i++;
		this._xmlHttpRequest.process(request);
	}
}catch(e){
	alert("gmaildom renameLabel\n" + e.toString());
}
};


GmailDOM.prototype.local = function(name){
try{
	switch(name){
		case "domain":
			return this._gtdinboxPage.doc.location.href.match(/^http(s?):\/\/mail.google.com\/(a\/.+?\/|.+?\/)/)[0];
		case "ik":
			return this._gtdinboxPage.unsafeWindow.top.js.ID_KEY;
		case "at":
			if( !this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine ) return "";
			var at = this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine.bfb;
			if( !at ) at = this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine.Fdb;
			if( !at ) at = this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine.Ehb;
			if( !at && this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine.MB ) at = this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine.MB.Fdb;
			if( !at ){
				for( p in this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine ){
					if( typeof this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine[p]=="string" && this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine[p].length>28 ){
						at = this._gtdinboxPage.unsafeWindow.top.js._GM_chatEngine[p];
					}
				}
			}
			return at;
		case "email-address":
			var email = this._gtdinboxPage.unsafeWindow.top.js.USER_EMAIL;
			if( (typeof email=="string") && email.indexOf("@")>-1 ){
				return email;
			}else{
				var elEmail = this.element("email-address");
				return (elEmail && elEmail.innerHTML.indexOf("@")>-1)? elEmail.innerHTML : "";
			}
	}
}catch(e){
	alert("gmaildom local\n" + e.toString());
}
	
	/* USE IN FIREBUG - replace the long string with whatever 'at' variable is sent when label added/renamed
	try{
	for( p in window ){
		if( typeof window[p]=="string" && window[p]=="xn3j2y6wakr0kcetvlj4zjkrqasotj" ){
			console.log(p);
		}else{   
			try{
			if( typeof window[p]=="object" ){
				for( p2 in window[p] ){
					if( typeof window[p][p2]=="string" && window[p][p2]=="xn3j2y6wakr0kcetvlj4zjkrqasotj" ){
						console.log(p + " - " + p2);    
					}else{
	for( p3 in window[p][p2] ){
	if( typeof window[p][p2][p3]=="string" && window[p][p2][p3]=="xn3j2y6wakr0kcetvlj4zjkrqasotj" ){
	console.log(p + " - " + p2 + " - " + p3);    
	}
	}
					}
				}
			}
			}catch(e){}
		}    
	}
	console.log("done");
	}catch(e){
	console.log(e);
	}
	
	*/
};